﻿using System;

namespace Borg.Logging
{
    public sealed class DesktopDispatcher : IDispatcher
    {
        private readonly IDispatcher _dispatcher;

        public bool IsDisposed
        {
            get { return _dispatcher.IsDisposed; }
        }

        public event DispatcherEventHandler DisposeStarted
        {
            add { _dispatcher.DisposeStarted += value; }
            remove { _dispatcher.DisposeStarted -= value; }
        }

        public event DispatcherEventHandler DisposeFinished
        {
            add { _dispatcher.DisposeFinished += value; }
            remove { _dispatcher.DisposeFinished -= value; }
        }

        public event UnhandledExceptionEventHandler UnhandledException
        {
            add { _dispatcher.UnhandledException += value; }
            remove { _dispatcher.UnhandledException -= value; }
        }

        public DesktopDispatcher()
        {
            _dispatcher = new Dispatcher(DesktopInvoker.Create());
        }

        public void BeginDispose()
        {
            _dispatcher.BeginDispose();
        }

        public void Dispose()
        {
            _dispatcher.Dispose();
        }

        public bool CheckAccess()
        {
            return _dispatcher.CheckAccess();
        }

        public void VerifyAccess()
        {
            _dispatcher.VerifyAccess();
        }

        public bool IsIdle()
        {
            return _dispatcher.IsIdle();
        }

        public IDispatcherOperation BeginInvoke(Delegate @delegate, params object[] @params)
        {
            return _dispatcher.BeginInvoke(@delegate, @params);
        }

        public object Invoke(Delegate @delegate, params object[] @params)
        {
            return _dispatcher.Invoke(@delegate, @params);
        }
    }
}
